package ar.uba.fi.algo3.java2d.ejemplo2;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Panel;

public class PanelMutante extends Panel implements Runnable{

	private static final long serialVersionUID = 1L;
	private boolean hayQuePintar;
	private int radio;
	private int incremento;
	private boolean estoyPintando;
	private int centroX;
	private int centroY;

	public PanelMutante(){
		this.radio = 20;
		this.incremento = 5;
		this.estoyPintando = false;
		this.hayQuePintar = false;
	}

	@Override
	public void run() {
		
		if(this.estoyPintando)
			return;
		
		this.centroX= (int) this.getWidth() / 2;
		this.centroY= (int) this.getHeight()/ 2;
		this.hayQuePintar = true;
		this.estoyPintando = true;
		while(hayQuePintar){
			try {
				Thread.sleep(25);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			this.centroX += this.incremento;
			if(this.centroX < 1 || this.centroX + this.radio > this.getWidth())
				this.incremento = this.incremento * -1;
			this.repaint();
		}
	}
				
	@Override
	public void paint(Graphics graphics){
		if(hayQuePintar){
			graphics.setColor(Color.BLUE);
			graphics.fillOval(this.centroX, this.centroY, this.radio, this.radio);
		}
		//super.paint(graphics);
	}	
}